<?php
namespace app\controller;

use think\Request;
use Curl\Curl;
use app\controller\Mobile as MobileController;
class Index extends MobileController
{
    public function index(Request $request)
    {
        $data   =   $request->param();
        $domain=$request->domain();
        if(!$request->has('url','get')){
            $data['url'] = 'hk';
        }
        if(!$request->has('plan','get')){
            $data['plan'] = 0;
        }
        $apiurl = 'http://kk0899.com/getdata?url='.$data['url'].'&plan='. $data['plan'].'&host='.$domain;
        $html = file_get_contents($apiurl);
        $json = json_decode($html,true);
//        if ($resjson['code'] == 200){
//            dd($json);
//        }else{
//            return '201';
//        }
//        dd($json);

        $mobile = $this->isMobile(); //实例化该方法
        if($mobile=="true"){
            if(!$request->has('plan','get')){
                return view('mobile', [
                    'cat_url'    =>  $data['url'],
                    'list'  =>  $json,
                ]);
            }else{
                return view('plan', [
                    'cat_url'    =>  $data['url'],
                    'list'  =>  $json,

                ]);
            }
        }else{
            return view('index', [
                'cat_url'    =>  $data['url'],
                'list'  =>  $json,

            ]);
        }
    }
    public function plan(Request $request){
        $data   =   $request->param();
        $domain=$request->domain();
        if(!$request->has('url','get')){
            $data['url'] = 'hk';
        }
        if(!$request->has('plan','get')){
            $data['plan'] = 0;
        }
        $apiurl = 'http://kk0899.com/getdata?url='.$data['url'].'&plan='. $data['plan'].'&host='.$domain;
        $html = file_get_contents($apiurl);
        $json = json_decode($html,true);
        return $json;

    }
}
